0
lyricsInp = document.getElementById("lyrics").value;
var lines = lyricsInp.split("\n");
for (i = 0; i < lines.length; i++) {
    holder[0][i] = new Array();
    words = lines[i].replace(/[ \t\r]+/g, "###").split("###");
    for (j = 0; j < words.length; j++) {
        holder[0][i][j].word = words[j];
        holder[0][i][j].startT = 0;
        holder[0][i][j].endT = 0;
    }
}

Here I need each holder element to keep word, startT and endT, but this does not work. How do I make this happen.

2
  • 1
    What is holder[0]? What does not work? Code seems fine (unless some uneccessary global variables) Commented Nov 1, 2012 at 15:13
  • Try ['word'] instead of .word ... or use a javascript object instead of an array. Commented Nov 1, 2012 at 15:14

3 Answers 3

1

Declare holder[0][i][j] as an object literal:

for (j = 0; j < words.length; j++) {
    holder[0][i][j] = {};

    holder[0][i][j].word = words[j];
    holder[0][i][j].startT = 0;
    holder[0][i][j].endT = 0;
}
Sign up to request clarification or add additional context in comments.

Comments

0
var holder = [[]];

var lyricsInp = document.getElementById("lyrics").value,
    lines = lyricsInp.split("\n");
for (var i = 0; i < lines.length; i++) {
    holder[0][i] = [];
    var words = lines[i].replace(/[ \t\r]+/g, "###").split("###");
    for (var j = 0; j < words.length; j++) {
        holder[0][i][j] = {
            word: words[j],
            startT: 0,
            endT: 0
        };
    }
}

Comments

0
lyricsInp =  document.getElementById("lyrics").value;
var lines = lyricsInp.split("\n");
for (i=0;i<lines.length;i++){
    holder[0][i] = new Array();
    words = lines[i].replace(/[ \t\r]+/g,"###").split("###");
    for (j=0;j<words.length;j++){
        holder[0][i][j] = {
                word: words[j],
                startT: 0,
                endT: 0
            };
    }
}

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.