Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

join last element of array javascript with different value

['tom', 'dick', 'harry'].join(', ').replace(/, ([^,]*)$/, ' and $1')
> "tom, dick and harry"
Comment

javascript array join last element with and

var a = ['a', 'b', 'c'];
var str = a.slice(0, -1).join(',')+' or '+a.slice(-1);
Comment

PREVIOUS NEXT
Code Example
Javascript :: localstorage setitem javascript 
Javascript :: expo android package name 
Javascript :: jquery on modal show 
Javascript :: jquery if input has empty white space 
Javascript :: chrome-doesnt-scale-below-x-500px 
Javascript :: how to format money as currency string 
Javascript :: gradle json simple dependency 
Javascript :: custom error nodejs 
Javascript :: javascript get element by multiple class 
Javascript :: get how much i scroll in js 
Javascript :: js class method called when page loads 
Javascript :: messageReactionAdd 
Javascript :: how to get element position in jquery 
Javascript :: how disabled react-select 
Javascript :: how to terminate a program in js 
Javascript :: javascript find object by property in array 
Javascript :: how to check if iframe is loaded 
Javascript :: remove first and last character from string javascript 
Javascript :: image on press 
Javascript :: autofocus react 
Javascript :: how remove child in jquery 
Javascript :: day of week javscript 
Javascript :: less than or equal js 
Javascript :: jetbrains font vscode 
Javascript :: implementating step component in react 
Javascript :: scroll to bottom of a div react 
Javascript :: strtotime in javascript 
Javascript :: add option to select jquery 
Javascript :: js cant find element 
Javascript :: select element by data attribute 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =