Skip to content

Instantly share code, notes, and snippets.

@JArmando
Created October 21, 2014 03:25
Show Gist options
  • Save JArmando/586fee20dbc9c836aace to your computer and use it in GitHub Desktop.
Save JArmando/586fee20dbc9c836aace to your computer and use it in GitHub Desktop.
#DevDo como crear un json a partir de texto
var texto = '1 Pablo Batida 2 soy una prueba';
var listaBonita = texto.split(/\d/g);
var jsonsito = '';
listaBonita.map(function(element, index){
jsonsito += element ? '{"'+ index + '":"' + element + '"}':''
});
console.log(jsonsito);
@JArmando
Copy link
Author

si... se puede hacer en dos lineas, pero para que los no iniciados tengan una idea de que esta sucediendo ahi...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment