Faire un implode / explode en javascript

Février 2013

split et join sont deux fonctions bien pratiques qui permettent de transformer une chaine de caractères (string) en tableau (array) et vice-versa.

Split : convertir string en tableau

Split est l'équivalent en Javascript de la fonction PHP explode, elle permet de découper une chaine en tableau avec un groupe de caractère séparateur et s'utilise comme cela :

var fruits_str   = "Fraise, Citron, Banane";
var fruits_array = fruits_str.split(", ");

On peut même lui passer un pattern (regex, expression régulière) en paramètre, pour avoir un découpage plus souple (on obtient alors un équivalent de preg_split, PHP) :

var fruits_str   = "Fraise, Citron, Banane";
var fruits_array = fruits_str.split(/\s*,\s*/);

Dans un tout autre contexte, cet article est très intéressant : mode protégé sur excel.

Join : convertir tableau en chaine

Join c'est la réciproque de split, elle est l'équivalent de implode en PHP et sert à créer une chaine par concaténation de tous les éléments d'un tableau (ou d'un objet) :

var fruits_array = ["Fraise", "Citron", "Banane"];
var fruits_str   = fruits_array.join(", ");

Encore faim ? allez lire ça : logo en origami !

3 commentaires :
commentaire n°3976 par sfofdnar@yandex.com
sfofdnar@yandex.com samedi 6 avril 2019, 12:45
Today anybody has an iOS tablet. This has lead to developing a millions of apks that provide servises such as games, development, entertainment playgrounds and others. To download any app a user must get an account at either Apple Store or Google Play. But not all apps are available there as they don't meet the official rules. To avoid this a new app was developed named TutuApp. This helper works both on Android and iOS run tablets and it has the biggest store of games. We name a few: Clash of Clans, Pokemon and others. They come with zero ads and locked content! Whant to know more? Visit <a href=https://tutuapp-app.com>;tutuapp-app.com</a> to download TutuApp for free on your iOS tablet. Installation instructions for the app are available at that page.
commentaire n°3990 par ewrdfrgew32f@yandex.com
ewrdfrgew32f@yandex.com mercredi 1 mai 2019, 07:35
Today almost every Internet user visits YT or any other video hosting provider to upload and watch funny videos, free movies and other content. But sometimes you want to download a video or a movie and the service doesn't allow you to do it. That's where Vidmate App is coming to help you out. It helps you to get a movie from may services, including Youtube, Vimeo, Vimeo and many other hosting services. To do this you simply need to open video page and click download button. Plus, Vidmate is free of charge and very easy in use with your Android! Download Vidmate APK from <a href=https://vidmateapp.pro/apk/>;this website</a> now and start downloading your favourite video to share them with your friends!
commentaire n°4011 par chrissf@yandex.com
chrissf@yandex.com mardi 14 mai 2019, 13:15
Chris Stapleton is my favourite US singer. His strong voice takes me away from all issues of this world so I start enjoy my life and listen songs created by his mind. Now the singer is on a All-American Road Show Tour started in May of 2019. The concerts scheduled for this year, up to the November 2. Tickets are available for all men and women with different income. If you love country music as mush as I, then you must visit at least one Chris' concert. All AMERICAN ROAD SHOW tour dates are available at the <a href=https://christapletontour.com>;Chris Stapleton tour 2019 LA</a>. Open the website and make yourself familiar with all powerful Chris Stapleton concerts in 2019!
facultatif
Facebook Twitter RSS Email
Forum Excel
Venez découvrir le nouveau forum excel question/réponse à la stackoverflow.com !
Forum Excel
hit parade n'en a rien a foutre du W3C Positionnement et Statistiques Gratuites Vincent Paré