Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只想搜索第一列myarray并返回索引:
myarray
示例搜索“s1”返回 0,搜索“s3”返回 1,依此类推
javascript
myarray = [ ['s1', 's2'], ['s3', 's4'], ['s5', 's6'] ]
感谢所有的帮助家伙...
解决方案
function searchCPL(what, find){ for(var i= 0, L= what.length; i<L; i++){ if(what[i][0]=== find) return i; } return ''; }; searchCPL(myarray, 'value');