0

I am trying to understand why when I run the following code, none of the props return as true for being arrays. addresses and emails should return true I would think, and yet they return false.

let obj1 = {
  name: 'John',
  age: 42,
  addresses: [],
  emails: []
}


function findArrays(obj) {
  for (let propName in obj) {
    console.log(propName, Array.isArray(propName));
    // All values console.log as false
 }
}

findArrays(obj1);

2 Answers 2

3

You iterate over the keys of the object (which are all strings, e.g. "emails"). The arrays are values of the object. To access the value stored under a specific key, use obj[propName].

Sign up to request clarification or add additional context in comments.

Comments

0

propName is string but obj[propName] is array.

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.