1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Add property to object only if it is not undefined

Discussão em 'Angular' iniciado por Kay, Agosto 14, 2025.

  1. Kay

    Kay Guest

    I have the following object:

    let params = {
    limit: limit,
    offset: 15,
    status: "completed",
    product_id: this.route.snapshot.queryParams.product_id,
    };


    The above object contain parameters that filter my data source.

    this.route.snapshot.queryParams.product_id is a query/get parameter


    ?product_id=123
    ​

    However if this value is not present it's undefined. So I do not want to add product_id member to the parameters object if this value is undefined.

    If it is undefined the object should look like:


    let params = {
    limit: limit,
    offset: 15,
    status: "completed",
    };

    Continue reading...

Compartilhe esta Página