-1

I'm fetching data in an array like this

[
    {
        "Id": 111,
        "Name": "Test 1",
        "Email": "email1@domain.net",
    },
    {
        "Id": 133,
        "Name": "Test 2",
        "Email": "null",
    },
    {
        "Id": 133,
        "Name": null,
        "Email": "email2@domain.net",
    }
]

from api

 this.Details = response;

i want to replace the value of null or blank with -.

user3653474
  • 3,393
  • 6
  • 49
  • 135
  • You can probably use the nullish coalescing operator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing Edit: Pertaining to the code sample you had in your question earlier -> `{{ row.Name ?? "No name"}}` – Jim Nilsson Dec 23 '22 at 08:29
  • "null" or null or both – cmgchess Dec 23 '22 at 08:31

1 Answers1

-1

You can do a conditional operator like &&

data[0].Name && console.log("There is a Name at 0");
data[1].Name && console.log("There is a Name at 1");
data[2].Name && console.log("There is a Name at 2");

const data = [
    {
        "Id": 111,
        "Name": "Test 1",
        "Email": "email1@domain.net",
    },
    {
        "Id": 133,
        "Name": "Test 2",
        "Email": "null",
    },
    {
        "Id": 133,
        "Name": null,
        "Email": "email2@domain.net",
    }
]


data[0].Name && console.log("There is a Name at 0");
data[1].Name && console.log("There is a Name at 1");
data[2].Name && console.log("There is a Name at 2");
Brandon
  • 389
  • 1
  • 8