💾arr.indexDictionaryForValues()
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS ⟩ objects ⟩ Array ⟩ methods ⟩ indexDictionaryForValues()
主要用於找 Google Sheet 的欄位索引 (column index)。
💾 replit
/*
* 🔸 array.indexDictionaryForValues(values)
* return the index for each value (a dictionary object)
*
* @example
*
* let row = ["座號", "姓名", "國語文", "英語文"];
* row.indexDictionaryForValues(["座號", "姓名"]) // { '座號': 0, '姓名': 1 }
*/
Array.prototype.indexDictionaryForValues = function(values){
💈範例:
let array = [12, 44, 22, 66, 222, 777, 22, 22, 22, 6, 77, 3];
let row = ["座號", "姓名", "國語文", "英語文"];
array.indexDictionaryForValues([777, 22]) // { '22': 2, '777': 5 }
row.indexDictionaryForValues(["座號", "姓名"]) // { '座號': 0, '姓名': 1 }
// row.indexDictionaryForValues(["沒這個值"]) // ⛔ Error