Javascript Array Class has an util function called isArray which we will use to determine given value is of array type then we can use array.length property to determine if an array is empty. Using in-built Array.isArray util function and length property of array this might lead to unexpected bugs in our code so in out next method we can solve this by checking if it’s of array type. ![]() Notice here we are not checking if given variable is array or not. So we will use this to check if our array is empty using Optional chaining operator on array’s length property. Javascript recently added Optional chaining operator and pretty cool and removes lot of code and increases the readability and shortens the code. ![]() ![]() Using Optional chaining operator and length property
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |