0

I have this kind of array:

var someArray = ['9213','9234'];

I want to do the following have the following result:

var obj = {
   9213:true,
   9234:true
}

How can i achieve this? something like:

obj = [];
_.each(someArray, function(currentNum,i){
     obj.push(); //here i should do something 
})
1
  • 2
    If you want an object ({}) why are you initialising an array ([])? Commented Oct 11, 2014 at 12:34

1 Answer 1

2

Like this:

obj = {}; // {} means object and [] means array
_.each(someArray, function(currentNum,i){
     obj[ currentNum ] = true;
     //by using [ currentNum ] you will create object property name as "9213" for example.
})
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.