0

How can I get the string name 'bar' instead of its contents ? Never found a solution for this one? I want console.log("?") to say 'bar'

let foo = [1,2,3], bar = [11,22,33], hello = [111,222,333]
    let arr = [foo, bar, hello]
    console.log(arr[1])
    // returns 11, 22, 33  ** I know this
    // I want it to return "bar" ?

2 Answers 2

1

As said above, you can't do this the way it is.

You could however, attach a name property to each base array.

For example:

const arr1 = [1,2,3], arr2 = [2,3,4];
arr1.name = "arr1";
arr2.name = "arr2";

const arrBoth = [arr1, arr2];

console.log(arrBoth[0].name);

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

1 Comment

Ah, that does look like it will make more sense this way if I can adjust the way I think about this problem. Sometimes you just need another perspective thats half the reason these sites are so helpful. Thanks. Ps. please give upTicks to those in need!! ))
1

As far as I know, you cannot do that. You might need to use an object for that

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.