小程序开发技巧(一) 获取长字符串中值为1的索引

 有这样一个需求,返回一个1024个字符的长字串,字串中只包含0或1,要返回所有值为1的索引。

var m_mp_status = res.data.obj.POINT_DNBYCQK.m_mp_status;
var result = [];
Array.prototype.forEach.call(m_mp_status, function(item, index) {
       if (item == 1) {
          result.push(index + 1);
       }
});

是不是比for循环要简单呢。

猜你喜欢

转载自blog.csdn.net/yuhan_0590/article/details/82910408