You could iterate the indices array and use a variable for getting the nested references.
var temp = myObject, // start value
indices = [2, 5, 3, 1],
i;
for (i = 0; i < indices.length; i++) {
temp = temp.conversations[indices[i]];
}
// use temp
console.log(temp);
I would just use .reduce
console.log(
[2,5,3,1].reduce(function(carry, current) {
return carry + '.conversations[' + current +']';
}, 'myObject')
)
I have two video sources that are outputted to my page via ajax (the second is hidden). I play the first one and bind an event onto it so that when it has ended the next video is played and shown ...
I have two video sources that are outputted to my page via ajax (the second is hidden). I play the first one and bind an event onto it so that when it has ended the next video is played and shown ...
I have an array with this loop: var arr = [5, 4, 9, 6, 4]; var sum = 0; arr.forEach(function(item) { sum += parseInt(item); console.log(sum) }); At the moment, I get ...
I have an array with this loop: var arr = [5, 4, 9, 6, 4]; var sum = 0; arr.forEach(function(item) { sum += parseInt(item); console.log(sum) }); At the moment, I get ...
I've built a page with 3 elements, each of which looks like this: <div class="col-md-4 event-type"> <a href="{{ pathFor 'step2' }}" id="eventchoice" name="eventchoice" value="corporate"> &...
I've built a page with 3 elements, each of which looks like this: <div class="col-md-4 event-type"> <a href="{{ pathFor 'step2' }}" id="eventchoice" name="eventchoice" value="corporate"> &...
is there an elegant way to determine, whether an array like this: [ {id: 1, value: false}, {id: 2, value: true}, {id: 3, value: false}, {id: 4, value: true}, {id: 5, value: true} ] ...
is there an elegant way to determine, whether an array like this: [ {id: 1, value: false}, {id: 2, value: true}, {id: 3, value: false}, {id: 4, value: true}, {id: 5, value: true} ] ...