題目描述
找出元素 item 在給定數組 arr 中的位置
輸出描述:
如果數組中存在 item,則返回元素在數組中的位置,否則返回 -1
示例1
輸入
[ 1, 2, 3, 4 ], 3
輸出
2
function indexOf(arr, item) { return arr.indexOf(item); }
如果數組中存在 item,則返回元素在數組中的位置,否則返回 -1
[ 1, 2, 3, 4 ], 3
2
function indexOf(arr, item) { return arr.indexOf(item); }
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。