How to get single values from object.values array?
I am getting this obj in console.log() // {"item": Array(3)}
{"item": (3) ['21', '14', '12']}
and I want to get single number from object.values // 21 ,14, 12
I am trying this
let j = Object.values(data)
console.log(j) // [Array(3)]
2
Answers
Since I am not sure what data is present in the variable
data
. Let’s assumej
is an array of elements.If you want to print each element in the array individually, you can use
forEach
This will print
or if you need to print all the elements in a single line without a loop, You can use
join
which will print
You can replace the
,
with whatever separator you wish to use.Object.values() function returns all values (of various properties) in an object — itself in an array.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values