How to check if a value is empty, or null in JavaScript?


Mr Robot:

I have a problem trying to get data from the state, 2 values ​​appear in console.log. I want to remove null values, but I've exhausted all methods. How to remove a null value?

1

class DetailOrderTracking extends Component {
    constructor(props) {
        super(props)
        this.state = {
            data: []
        }
    }

    componentDidMount = async () => {
        const { query } = this.props.router;
        var getOrderTrackings = await OrderTrackingRepository.getOrderTracking(query.numberbill, query.courier);
        if (getOrderTrackings.ordertracking.status.code == 200) {
            var getManifest = getOrderTrackings.ordertracking.result.manifest;
            this.setState({ data: getManifest });
        }
    }

    render() {
        const { data } = this.state;
        console.log(data) // will print 2 values, first condition is empty value, and second condition has values (an example is in the image above)
        return (
            <div/>
        )
    }
}
Danilo twenty-five:

should do:

    render() {
        const { data } = this.state;
        if (data.length > 0){
          console.log(data)
        }
        return (
            <div/>
        )
    }

Related


How to check if a value is empty, or null in JavaScript?

Mr Robot: I have a problem trying to get data from the state, 2 values appear in console.log. I want to remove null values, but I've exhausted all methods. How to remove a null value? class DetailOrderTracking extends Component { constructor(props) {

How to check if a value is empty, or null in JavaScript?

Mr Robot: I have a problem trying to get data from the state, 2 values appear in console.log. I want to remove null values, but I've exhausted all methods. How to remove a null value? class DetailOrderTracking extends Component { constructor(props) {

Check model value is null or empty in javascript

Ze this is my code <script> var _getValue = @myViewModel.myInfo.Name == null ? 'isNull' : 'notNull'; </script> @myViewModel.myInfo.NameThe value in the database is empty, but this code always returns notNull. How can I properly check for null or null? Niti

How to check if value in JS is not null and not empty string

mistery_girl: Is it possible to check if a value is not null and not an empty string in Java? I am using one of the following: var data; //get its value from db if(data != null && data != '') { // do something } But I wonder if there is another better sol

How to check if value in JS is not null and not empty string

mistery_girl: Is it possible to check if a value is not null and not an empty string in Java? I am using one of the following: var data; //get its value from db if(data != null && data != '') { // do something } But I wonder if there is another better sol

How to check if value in JS is not null and not empty string

mistery_girl: Is it possible to check if a value is not null and not an empty string in Java? I am using one of the following: var data; //get its value from db if(data != null && data != '') { // do something } But I wonder if there is another better sol

How to check if Javascript object value is an array and not empty

beat Before running some code, I need to check that the data I'm passing (from a JSON file) is correct. Specifically, I'm trying to check if the email exists and my body object: - has at least one key - each key has a value - and the value must be an array wit

How to check if Javascript object value is an array and not empty

beat Before running some code, I need to check that the data I'm passing (from a JSON file) is correct. Specifically, I'm trying to check if the email exists and my body object: - has at least one key - each key has a value - and the value must be an array wit

Javascript how to check if input value is empty or not a number?

Emmanuel I want to check the value entered by the user in one of my inputs. I want to check that the value entered is neither an empty string nor a number. What should I do please? const tempInput = parseInt(document.querySelector("#temp").value); // this is

Check if seekbar value is null or empty

artist I am trying to check if the value of seekbar is less than 0. Currently my seekbar has a value between 0-9. seekbar1 = (SeekBar)findViewById(R.id.sb); seekbar1.setOnSeekBarChangeListener( new OnSeekBarChangeListener(){ @Override public void onPr

Check if property value is null or empty

· 鲍德尔 (Bishnu Paudel I'm having trouble processing JSON data with PHP in Oracle RightNow CRM. Example json is included below. When I try to check the if condition, the data contained in the "person.private_email" property only evaluates to true if some data is

Check if seekbar value is null or empty

artist I am trying to check if the value of seekbar is less than 0. Currently my seekbar has a value between 0-9. seekbar1 = (SeekBar)findViewById(R.id.sb); seekbar1.setOnSeekBarChangeListener( new OnSeekBarChangeListener(){ @Override public void onPr

Check if property value is null or empty

· 鲍德尔 (Bishnu Paudel I'm having trouble processing JSON data with PHP in Oracle RightNow CRM. Example json is included below. When I try to check the if condition, the data contained in the "person.private_email" property only evaluates to true if some data is

Check if property value is null or empty

· 鲍德尔 (Bishnu Paudel I'm having trouble processing JSON data with PHP in Oracle RightNow CRM. Example json is included below. When I try to check the if condition, the data contained in the "person.private_email" property only evaluates to true if some data is

How can I check if my value is null or empty?

EColi In my JSP code I have the following: <s:iterator value="details" id="cle" status="rowCle"> <s:iterator value="value" status="row" > <tr> <s:if test="%{#surname== ''}"> <td>&nbsp;</td> </s:if> <s:else> <td

How to check int is not null or empty?

User 405398: I really don't know if this is possible. But I make a call at a place where I want to check if an int value is correct nullto call a different method. What is the solution? Actually, the variable comes from the browser with the nullvalue . I can't

How to check if IEnumerable is null or empty?

Schultz 9999 I love string.IsNullOrEmptymethod. I'd love to have something that provides the same functionality for IEnumerable. Do you have? Maybe some collection helper class? The reason I'm asking is that the code in the statement looks messy ifif the state

How to check int is not null or empty?

User 405398: I really don't know if this is possible. But I make a call at a place where I want to check if an int value is correct nullto call a different method. What is the solution? Actually, the variable comes from the browser with the nullvalue . I can't

How to check if IEnumerable is null or empty?

Schultz 9999 I love string.IsNullOrEmptymethod. I'd love to have something that provides the same functionality for IEnumerable. Do you have? Maybe some collection helper class? The reason I'm asking is that the code in the statement looks messy ifif the state

How to check int is not null or empty?

User 405398: I really don't know if this is possible. But I make a call at a place where I want to check if an int value is correct nullto call a different method. What is the solution? Actually, the variable comes from the browser with the nullvalue . I can't

How to check if IEnumerable is null or empty?

Schultz 9999 I love string.IsNullOrEmptymethod. I'd love to have something that provides the same functionality for IEnumerable. Do you have? Maybe some collection helper class? The reason I'm asking is that the code in the statement looks messy ifif the state