Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
4472
4473 if (S.rows.length == 0) { return A }
4474
4475 for (const key in B) {4476 A[key] = B[key]4477 }4478
4479 for (let i = 0; i < S.fields.length; i++) {
4480 A[S.fields[i]] = S.rows[0][i]
Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
2389 const rec = $('#' + rows[row].obj)
2390
2391 if (arrFilter !== null) {
2392 for (const columnId in arrFilter) {2393 const data = []2394 data.val = nuSubformFilterCellValue(sfName, columnId, row)2395 data.filter = arrFilter[columnId].value2396 data.type = arrFilter[columnId].type2397 data.optionAll = arrFilter[columnId].all2398 data.optionBlank = data.filter == '' && data.type == 'search'2399 data.isMatch = (data.type == 'search' && data.val.toLowerCase().includes(data.filter.toLowerCase())) ||2400 (data.type == 'select' && (data.val.toLowerCase() == data.filter.toLowerCase() || data.optionAll))24012402 if (window.nuSubformOnFilterRows) {2403 hide = nuSubformOnFilterRows(sfName, data, row, rows.length)2404 } else {2405 if (!data.isMatch && !data.optionBlank && rows.length - 1 !== row) {2406 hide = true2407 break2408 } else {2409 hide = false2410 }2411 }2412 }2413 }
2414
2415 if (hide === false) {
Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard
2167 const arr = {}
2168 const isArray = Array.isArray(arrColumns)
2169
2170 for (let columnId in arrColumns) {2171 if (isArray) columnId = arrColumns[columnId]2172 arr[columnId] = {}2173 arr[columnId].type = isArray ? 'select' : arrColumns[columnId].type2174 arr[columnId].value = nuSubformFilterValue(sfName, columnId, arr[columnId].type)2175 arr[columnId].all = nuSubformFilterOptionAll(sfName, columnId)2176 }2177
2178 return arr
2179 }
Description
Looping over objects with a for in
loop will include properties that are inherited through the prototype chain.
This behavior can lead to unexpected keys in your for loop.
Bad Practice
for (const key in foo) {
doSomething(key);
}
Recommended
for (const key in foo) {
if (Object.prototype.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}
for (const key of Object.keys(foo)) {
doSomething(key);
}