Skip to main content

Featured post

How to Insert line break in Text component in React Native

Hi, I was developing an application in react native.I have to handle lots of text data in this small react native application.I have used  Text component in react native many times. While working on this application,i had a requirement to display some text content with line breaks.I will explain it clearly with an example.I want to display a text as shown below  Welcome Please subscribe my channel I wrote react native code as shown below <View> <Text> Welcome Please subscribe my channel </Text> <View> When i run these lines of code,It will display text as shown below Welcome Please subscribe my channel   - instead of displaying in two lines with line break,it displays in a single line.So i have to find a solution to insert line break in Text component in React Native.After lots of research,i found a clean solution as shown below <View> <Text> Welcome{"\n"} Please subscribe my channel </Text> <View> Here ...

How to check a javascript array is empty or not empty using length property of array

In this article, i will explain How to check an array is empty or not empty using length property of array.If an array has no elements ,then its length property is zero .If an array has elements,then its length property is the number of elements in that array .So using length property of array, we can easily check that the given array contains any elements


let numsArray1 = [];


if(Array.isArray(numsArray1) && numsArray1.length >0){

   console.log("numsArray1 is  not an empty array")

}else{

    console.log("numsArray1 is  an empty array")

} //numsArray1 is  an empty array




let numsArray2 = [1,2,3];


if(Array.isArray(numsArray2)  && numsArray2.length >0){

   console.log("numsArray2 is  not an empty array")

}else{

    console.log("numsArray2 is  an empty array")

}  //numsArray2 is  not an empty array








Here i have declared two arrays numsArray1 and numsArray2. In both cases first we check numsArray1 and numsArray2 are javascript arrays using isArray method of Array in javascript. numsArray1 has no elements.So its length property has the value 0.So  It is an empty array.We got the result as numsArray1 is an empty array. But numsArray2 has 3 elements.So its length property has the value 3. So numsArray2 is not an empty array