Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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"]
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
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"}]?