Michael Unterthurner
Michael Unterthurner

Reputation: 941

Clueless about how to change an item in array

I have an array and am adding to this array a JavaScript object.

var channels = [];
var channel = {
    id: data.channels[i].id,
    name: data.channels[i].name,
    head_name: groups[data.channels[i].group-1],
    show_title: show_group_title             // var show_group_title = false;
}
channels.push(channel);

Now I want to change the show_title of the first array from false to true. How I could do that?

enter image description here

Upvotes: 0

Views: 68

Answers (2)

eonj
eonj

Reputation: 119

I don't understand what behavior do you expect... Do you need something like this?

var channel = {
    id: data.channels[i].id,
    name: data.channels[i].name,
    head_name: groups[data.channels[i].group-1],
    show_title: function() { return groups_show_title[data.channels[i].group-1]; }
    // or just
    // show_title: groups_show_title[data.channels[i].group-1]
}

This code needs an additional array.

Upvotes: 0

Denys Séguret
Denys Séguret

Reputation: 382132

You seem to want

channels[0].show_title = true;

Upvotes: 2

Related Questions