If you want to know if there is at least 1 value:
- undefined or null (
== null)
- or empty (
=== "")
you should use findIndex on object's values.
if ( -1 !== Object.values(widget).findIndex( v => v == null || v === "") )
alert("missing value found!");
Note that find is not appropriate because you would not know what it means when it return undefined.
[EDIT with your code]
You misuse map. map is when you want to return an array of same length and work on its transformed elements. Here your function returns nothing.
If you want to return an array with less elements (e.g. matching an id), use filter.
If you want to return anything else (e.g. sum of all elements), use reduce.
If you want to return nothing (void) and just loop through array, use forEach.
If you want to check if an element has a property, use find or findIndex.
From what I understand, your function could be:
handleGobackToBoards = () => {
const boardList = this.props.storyboardList.boardList,
boardId = this.props.selectedBoard.boardId;
boardList
.filter( (data) => data.boardId === boardId ) // Get all board with matching id
.forEach( (data) => {
data.widgetList
.filter( (widget) => widget.widgetId ) // Get all widgets that have an id
.forEach( (widget) => {
if ( -1 !== Object.values(widget).findIndex( v => v == null || v === "") ) {
alert('Empty Data');
}
else {
this.props.manageShowBoard({});
}
});
});
}
[EDIT2] Something that is not equivalent to your code, but I guess closer to what you want to do:
handleGobackToBoards = () => {
const boardList = this.props.storyboardList.boardList,
boardId = this.props.selectedBoard.boardId,
board = boardList.find( (data) => data.boardId === boardId ); // Get board with matching id
if (!board)
return; // No matching board
const emptyWidget = board.widgetList.find( (widget) => -1 !== Object.values(widget).findIndex( v => v == null || v === "") );
if (emptyWidget)
alert('Empty Data');
// All widgets have no empty property, show board
this.props.manageShowBoard({});
}