を混ぜ、私は例えば、文の内部索引スペースのための連想配列を作成しました:各&ループのための私の配列順序
文:こんにちは どのようにあなたは? 、
indexed_words[0] = hello
indexed_words[0_1] = space
indexed_words[0_2] = space
indexed_words[0_3] = space
indexed_words[0_4] = space
indexed_words[0_5] = space
indexed_words[0_6] = space
indexed_words[0_7] = space
indexed_words[1] = how
indexed_words[2] = are
indexed_words[3] = you?
が、私は「for」ループを使用する場合、そのインデックス0(アラートを使用して)私を示しています(「どのように」と単語の間のスペース「ハロー」)
はので、私の配列は次のようになります1,2,3最初とその後、サブインデックス、それは私の配列の順序、任意のアイデアを混在?
ここに私のコード:
function words_indexer(user_content)
{
var words_array = user_content.split(" ");
var indexed_words = {};
var word_counter = 0
var last_word_counter = 0
$.each(user_content, function(word_key,word_value){
if(word_value === ''){
var indexed_key = last_word_counter + '_' + word_key;
indexed_words[indexed_key] = word_value;
}else{
var indexed_key = word_counter;
indexed_words[indexed_key] = word_value;
last_word_counter = word_counter;
word_counter++;
}
});
for (var key in indexed_words) {
alert(key + ' ' + indexed_words[key]);
}
}
達成したいことを追加してください。 –