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 :: generate uuid 
Javascript :: how to change the text of a paragraph 
Javascript :: Does my number look big in this? js 
Javascript :: image and video lightbox react 
Javascript :: loop over a nerber in react 
Javascript :: puppeteer block request javascript 
Javascript :: puppeteer set up code 
Javascript :: vue method 
Javascript :: mail testing 
Javascript :: jquery if in page 
Javascript :: build react app 
Javascript :: currenttarget javascript 
Javascript :: js export options 
Javascript :: js reading file 
Javascript :: axios get array of urls 
Javascript :: how to call function on every keypress in jquery 
Javascript :: what is dotenv in nodejs 
Javascript :: closure in javascript 
Javascript :: get unique id angular 
Javascript :: js localstorage clear 
Javascript :: label animation css 
Javascript :: make forn awesome icon clickable in react 
Javascript :: make image onclick in vuejs 
Javascript :: vuejs on route scrollbehavior 
Javascript :: Counting instances of values in an object 
Javascript :: scroll top javascript 
Javascript :: JavaScript Destructuring - From ES6 
Javascript :: Least common multiple from array 
Javascript :: create javascript map 
Javascript :: toast js 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =