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 an object is empty in javascript

As a programmer, we need to handle objects in our daily life.So there should be some cases where we have to check the given object is empty.Empty objects mean there is no keys  for that object.In this blog post I am going to explain How we can easily identify an object is empty or not in javascript


let obj1 ={}


console.log(Object.keys(obj1));    // []


if(Object.keys(obj1).length === 0)

{

    console.log("obj1 is an empty object")

}else{

    

    console.log("obj1 is not an empty object")

}   // obj1 is an empty object





let obj2 ={  name : "Technursery" , visitors : 1000}


console.log(Object.keys(obj2));  // [ 'name', 'visitors' ]


if(Object.keys(obj2).length === 0)

{

    console.log("obj2 is an empty object")

}else{

    

    console.log("obj2 is not an empty object")

}  //obj2 is not an empty object




In the above code, I created two objects obj1 and obj2. obj1 is an object which has no key. So we got an empty array  for keys  and result is obj1 is an empty object .But obj2 is an object which has two keys. So we got an array with two keys as shown in the above code.So obj2 is not an empty object