How can I pass a javascript object to string?

0

I have an object in Javascript with different attributes, some of them are arrays .

I would like to know if there is any function of any kind style. toString() to return a text string with all the data.

Example:

let partida = {
  usuarioCreador: "..",
  estado: "..",
  jugadores: [...],
  ..
  }

//cadena de texto deseada
let salida = "[ "propAtributo1","propAtributo2",["propiedadesAtributo 3"],"propAtributoN" ]";
    
asked by Jroman 27.01.2018 в 10:18
source

1 answer

2

/* Ejemplo */
 var obj=
 {
    UsuarioCreador:"Javier",
    Codigo:"090F",
    Tema:"JavaScript"
 };
 
 /* stringify convierte el objeto 'obj' a una cadena JSON */
 console.log(JSON.stringify(obj));
 console.log(typeof (JSON.stringify(obj)));
    
answered by 27.01.2018 в 11:17