Created
August 21, 2019 15:57
-
-
Save parzibyte/ee93ca1243d628253e6e64b27a449a69 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Extraer parte de una cadena con JavaScript | |
* | |
* @author parzibyte | |
* | |
* https://parzibyte.me/blog | |
*/ | |
let cadena = "JavaScript es un lenguaje muy bueno"; | |
// Buscamos el índice del espacio | |
// https://parzibyte.me/blog/2018/12/04/buscar-indice-posicion-elemento-arreglo-javascript/ | |
let indice = cadena.indexOf(" "); | |
// Cortar desde 0 hasta la aparición del primer espacio | |
let extraida = cadena.substring(0, indice); | |
console.log("Extraída: ", extraida); | |
/* | |
Salida: | |
Extraída: JavaScript | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment