So I have this code written in ES6
let documents = somedata;
if (documents.length >= 0) {
documents.map( (item, index) => {
state[item.type].push(item);
});
this.setState({documents: state});
}
and I'm trying to optimize it, do I need to check the length of an array before declaring an mapping, what would be a better way to handle error checking?
Like is there any instance in which not checking for the length would be bad?
If the variable wasn't an array it would fail, but are there any cases besides that I should be worried about?