Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I am getting API response as:
[{"subject1": "English", "subject1": "Maths"}]
I want to store the values (English and Maths) into an array without keys like:
English
Maths
subject = ["English", "Maths"]
[{"subject1":"English"}, {"subject1":"Maths"}]
maybe this solve your problem:
// if you have variable number of subject let res = [{"subject1":"English", "subject2":"Maths"}] let subjects = [] for(prop in res[0]){ subjects.push(res[0][prop]) } console.log(subjects)
Add a comment
Does this solve your problem?
subject = []; subject.push(Object.values(response));
Given an array of objects:
Use this:
let res = foo.map(e => e.subject1) console.log(res) // prints ["English", "Maths"]
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
[{"subject1":"English"}, {"subject1":"Maths"}]?