JavaScript by Radu TM • June 21, 2022
const arr = ['a', 'b', 'c', ''];
// loop through arr
for (let i = 0; i < arr.length; i++) {
// if the current element is an empty string
if (arr[i] === '') {
// print a message to the console
console.log('The array contains an empty string.');
// stop the loop
break;
}
}
0
20.900
JavaScript by Radu TM • June 21, 2022
const checkForEmptyString = (arr) => {
// return true if any element in arr is an empty string
return arr.some((element) => {
return element === "";
});
};
0
20.900
JavaScript by Radu TM • June 21, 2022
const arr = ['', 'not empty', 'also not empty']
arr.forEach(element => {
if (element === '') {
console.log('empty string found')
}
})
0
20.900