我有一個包含的數組const submissions = [{ question: 'blah blah blah blah', response: 'response goes here'},我有一個接受提交數組和字符串的函數。我需要檢查響應提交 [i].response 對字符串。如果存在則返回 true。let submissions = [{ question: 'blah blah blah blah', response: 'response goes here'}];function checkString(submissions, string) { for (let i = 0; i < submissions.length; i++) { if (submissions[i].response === string) { return true; } } return false;}console.log(checkString(submissions,'response goes here'));如果調用函數 checkString(submissions, 'response goes here') 應該返回 true。這總是返回 false。
比較 array[i].response 到通過函數參數傳遞的字符串
慕姐8265434
2022-12-22 13:47:27