Modelesq Modelesq - 2 years ago 449
Javascript Question

ES6 conditional if statement to check if arrays are empty

I can't seem to get my jsx es6 react if statement to work.. What am I doing wrong?

const otherVariables = doesntMatter;

return (
{if (props.student.length == null && props.teacher.length == null) => (
) : (
<p>not empty</p>

How can i check if both arrays are empty?

Answer Source

There is a syntax error, you are testing an lambda expression.

You can do something like

return !!props.student.length && !!props.teacher.length ? <p>not empty</p> : <p>empty</p>;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download