-5

I have a string with comma now i want to get first value how can i get it?

My Code:-

var data = "0.46609362959861755, 0.25069287419319153, 0.5107838958501816, 0.26014574989676476";

console.log(data.replaceAll(',','').splice(0,2));

Thanks for your efforts!

Rohit Verma
  • 3,657
  • 7
  • 37
  • 75

2 Answers2

2

Maybe you need this?

data.split(',')[0]
RenaudC5
  • 3,553
  • 1
  • 11
  • 29
1
console.log(data.split(', ')[0])

Use this instead of what you did.

data.split(', ')

returns an array with every element in your string, separately, with no spaces or commas attached. The [0] after it grabs the first element of the array.

Jonas
  • 416
  • 4
  • 12