-3

If I have an array:

const arr = ['this', 'is', 'my', 'test'];

How can I dynamically do

myObj[arr[0]][arr[1]][arr[2]]
4

1 Answer 1

1

I am not sure if this is what you are looking for? enter link description here

const arr = ['this', 'is', 'my', 'test'];
var Obj = arr.join(" ");
console.log(Obj)

--------------------------------please see this as updated ---------------------

const arr = ['this', 'is', 'my', 'test'];

var Obj = [];
var i;
for (i = 0; i < arr.length; i++) {
  Obj.push([arr[i]])
}
Sign up to request clarification or add additional context in comments.

4 Comments

actually i want to do this myObj[arr[0]][arr[1]][arr[2]] join will make it something like myObj[this is my test] i want myObj['this']['is']['my']['test']
then you could do var Obj = [[arr[0]],[arr[1]],[arr[2]]];
yes exactly but i need to do this dynamically not manually
i updated in my previous answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.