Created
October 29, 2019 20:01
-
-
Save romaefGit/ea04719427a56658ff430dcea696371e to your computer and use it in GitHub Desktop.
JavaScript - Crea un array de items tipo Object en un String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Romario Augusto Estrada Flórez - romarioestrada.ff@hotmail.com | |
| * [ArrayMakeStringCSV esta función recibe un arreglo y el nombre de la propiedad, | |
| * de la cual quiere armar un string separado por comas. | |
| * example : recibe -> [{id: 2, nombre:'algo'}, {id: 1, nombre:'algo 2'}]] | |
| * si envian ese arreglo y le dicen el nombre del campo 'id' (arrerglo, 'id'), | |
| * devolverá: '2,1'; | |
| * @param {[Array]} arreglo [El arreglo de items tipo Object] | |
| * @param {[String]} nombreCampo [el nombre de la propiedad] | |
| * @return {[String]} [Una cadena separada por comas] | |
| */ | |
| $scope.ArrayMakeStringCSV = function(arreglo, nombreCampo) { | |
| var newArrayIds = []; | |
| for (var i = 0; i < arreglo.length; i++) { | |
| newArrayIds.push(arreglo[i][nombreCampo]); | |
| } | |
| var stringIds = newArrayIds.toString(); // los ids de la empresas separados por coma | |
| // console.log(stringIds); | |
| newArrayIds = []; | |
| return stringIds; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment