0

I'm trying to use push method to add this object arrayObject to newArrayCheck but the values property comes out as [[array] [array]] in instead of [[1,2],[5,6]]. How can I use push method to add the correct value for the value property which is [[1,2],[5,6]].

arrayObject =[ {
    obj : "King",
    values : [[1,2],[5,6]]
}];

newArrayCheck = []
for (let i of arrayObject){
    newArrayCheck.push(i);
};
console.log(newArrayCheck);

Out Put: enter image description here

2
  • 1
    Your code is working as you think it is. However, node.js is hiding some things so that you can see the overall picture. If you want details, inspect newArrayCheck[0] instead, so node won't feel the need to simplify the display. Commented Feb 9, 2021 at 3:39
  • 1
    use console.log( JSON.stringify( newArrayCheck) ); Commented Feb 9, 2021 at 3:44

1 Answer 1

1

The implementation is correct and you are allowed to do so.

You can stringify the array for quick view by console.log(JSON.stringify(newArrayCheck[0].values));

You will get the values if you iterate over the values property.

If you are trying to access the value use:

for (let obj of newArrayCheck) {
    for (let value of obj.values) {
        console.log(value)
    }
}

You can even use map:

newArrayCheck.map(obj => {
    obj.values.map(value => {
        console.log(value)
    })
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.