Want to find index of empty object in array of object? You can make use of findIndex and Object.keys():
1 2 3 4 5 | const arr = [{a:'b'}, {}]; const emptyIndex = arr.findIndex((obj) => Object.keys(obj).length === 0); console.log(emptyIndex); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.