-3
const data = [{
"hello":'thameem',
"age":24
},
{
"hello":'thameem',
"age":25
}];
console.log(data);

I need all age values

Lain
  • 3,657
  • 1
  • 20
  • 27

2 Answers2

2

let data = [{ "hello":'thameem', "age":24 }, { "hello":'thameem', "age":25 }];

// will give you an array to ages
data = data?.map(item => item.age)

0

Use map to create an array

const ages = data.map((d) => d.age);
console.log(ages);

If you don't need new array and just want to access the property, you may use forEach

data.forEach((d) => {
  // do something with your data
}
MrBens
  • 1,227
  • 1
  • 9
  • 19