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;
}
}
在这里,我需要每个持有人元素保留word,
startT
和endT
,但这不起作用。我该如何实现这一目标。
答案 0 :(得分:1)
将holder[0][i][j]
声明为对象文字:
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;
}
答案 1 :(得分: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
};
}
}
答案 2 :(得分: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
};
}
}