在javascript中计算字符串字符总是返回1

时间:2015-08-29 17:35:01

标签: javascript facebook

大家好,如果在朋友列表页面上执行,此代码用于拥有Facebook好友或受邀朋友的列表名称和ID。我试图在javascript中计算字符串的字符,但.length方法总是返回1.我不明白为什么因为我指的是字符串而不是数组。

这是我的代码:

var name_list;
var id_list;
var count_letter_l;
var count_name = 0;
var count_id = 0;


var inputs = document.getElementsByClassName('_2akq _1box'); 

for(var i=0;i<inputs.length;i++){

  var name = inputs[i].getElementsByTagName('span')[0].childNodes[0].nodeValue;
  var full_id = inputs[i].getAttribute("data-reactid");
  var split_id = full_id.split(':');
  var split_two = split_id[1].split('.');
  var split_final = split_two[0];



  var count_letter = split_final.length;
  //console.log(count_letter);

  if(name != 'null'){
    name_list+= ',' + '"' + name + '"';
    id_list += ',' + '"' + split_final + '"';
    count_letter_l += ',' + '"' + count_letter + '"';
    count_name++;
    count_id++;
  }

}

console.log(name_list);
console.log('------!!!!!!!!------');
console.log(id_list);
console.log('names = ' + count_name);
console.log('id = ' + count_id);
console.log('letters for esch field = ' + count_letter_l);

我想在我的情况下计算每个id原因的字符,当我抓住id时,我在列表中有一些“0”和“1”。我不知道为什么,我希望将它们从列表中删除。

这是_2akq _1box类的元素。你可以看到它如果打开firefox firbug并在显示朋友列表时查看facebook前端html代码

<span class="_2akq _1box" data-reactid=".5q.2.0.0.0.0:0:1:$1543522353.0.0.$2.$text.0.0">
<span data-reactid=".5q.2.0.0.0.0:0:1:$1543522353.0.0.$2.$text.0.0.0">Laura Casali</span>
</span>
控制台告诉我:

letters for esch field = undefined,"1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1".....

tnx寻求帮助

0 个答案:

没有答案