-1

I have this JSON Array:

const arr = [ 
    { data: '250', name: 'john' },
    { data: '251', name: 'john' }
]:

How can i get from it, to a single new array having [250, 251] ?

I am not able to solve this.

Swiffy
  • 4,401
  • 2
  • 23
  • 49

2 Answers2

1

let arr = [ { data: '250', name: 'john' }, { data: '251', name: 'john' } ];
let result = arr.map((x) => x.data);
console.log(result);
Swiffy
  • 4,401
  • 2
  • 23
  • 49
-1

let arr = [
  { data: "250", name: "john" },
  { data: "251", name: "john" },
];
let result = arr.map((x) => x.data);
console.log(result);

let list = [];
for (let i = 0; i < arr.length; i++) {
  list.push(arr[i].data);
}

console.log(list);
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Ethan Jun 17 '22 at 22:24