Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify a string in JavaScript

I want to modify the color attribute that is returned in JQuery. So, lets assume the color is returned and is contained in a

var color
color = 'rgb(148, 141, 124)'

I want to modify the value of color to be:

color = 'rgb(148, 141, 124, .7)'

(in other words, insert the string ", .7")

like image 614
sea26.2 Avatar asked Feb 12 '23 15:02

sea26.2


1 Answers

Try,

var color = 'rgb(148, 141, 124)';
var newColor = color.slice(0,-1) + ",.7)"

DEMO

If you want it to be rgba then use,

var color = 'rgb(148, 141, 124)';
var newColor = (color.slice(0,-1) + ",.7)").split('(').join('a(');

DEMO

like image 151
Rajaprabhu Aravindasamy Avatar answered Feb 15 '23 05:02

Rajaprabhu Aravindasamy