this is my first array
data= [{
"id":1111,
"date":"2020-08-03T08:00:00+00:00",
"age":23,
"email":"[email protected]",
"address":"phill road",
"salary":1222.00
},
{
"id":222,
"date":"2020-08-03T08:00:00+00:00",
"age":24,
"email":"[email protected]",
"address":"phill2222 road",
"salary":3344
}
]
second array should look like this
dataNew= [1222.00,3344]
I need second array that only contain the salary value . How can I filter the first array, that if the keys name = "salary" , push the value to new array. Searched for so many suggestion, but nothing seems working for me..
data= [{
"id":1111,
"date":"2020-08-03T08:00:00+00:00",
"age":23,
"email":"[email protected]",
"address":"phill road",
"salary":1222.00
},
{
"id":222,
"date":"2020-08-03T08:00:00+00:00",
"age":24,
"email":"[email protected]",
"address":"phill2222 road",
"salary":3344
},
{
"id":223,
"date":"2020-08-03T08:00:00+00:00",
"age":24,
"email":"[email protected]",
"address":"phill2222 road"
}
]
console.log(data.filter(e => e.salary).map(e => e.salary));
data= [{
"id":1111,
"date":"2020-08-03T08:00:00+00:00",
"age":23,
"email":"[email protected]",
"address":"phill road",
"salary":1222.00
},
{
"id":222,
"date":"2020-08-03T08:00:00+00:00",
"age":24,
"email":"[email protected]",
"address":"phill2222 road",
"salary":3344
}]
console.log(data.map(item => item.salary))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With