2 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
你是這個(gè)意思?
var arr = [2, 6, 4, 4, 4, 9]
var newArr = (arr.sort())
var rem = []; // create your rem array outside
for (var i = 0; i < newArr.length; i++) {
if (newArr[i] == newArr[i + 1]) {
rem.push(i); // if "i" matches your criteria, add it to the array.
}
}
console.log(rem); // rem has the full list of indices

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊
也許是這樣的?
var arr = [2, 6, 4, 4, 4, 9]
var newArr = (arr.sort())
vare rem = []
for (var i = 0; i < newArr.length; i++)
if (newArr[i] == newArr[i + 1]) {
rem.push(newArr[i]);
}
console.log(rem[0])
添加回答
舉報(bào)