0

If I have an array such as:

let arr = [{subject: "BSE", courseCode: "1010"},{subject: "STA", courseCode: "2020"}];

Is it possible to make the array only containing the value pairs of the object such as:

let result = ["BSE","1010","STA","2020"];
1
  • Object.values(Obj) gives you the list of values for Obj Commented Nov 10, 2020 at 4:07

1 Answer 1

2

Using Object.prototype.values, you can generate only values from an object.

let arr = [{subject: "BSE", courseCode: "1010"},{subject: "STA", courseCode: "2020"}];

const output = arr.flatMap((item) => Object.values(item));
console.log(output);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.