Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last part of CSV string

Say I have a CSV string:

red,yellow,green,blue

How would I programatically select blue from the string using jQuery?

The data is returned via an AJAX request from a PHP script rendering a CSV file.

var csv_Data;

$.ajax({ 
    type: 'GET', 
    url: 'server.php',
    async: false,
    data: null, 
    success: function(text) { 
        csv_Data = text;
    } 
}); 

console.log(csv_Data);
like image 793
Xavier Avatar asked Dec 16 '22 11:12

Xavier


1 Answers

You can use split() and pop():

var lastValue = csv_Data.split(",").pop();  // "blue"
like image 67
Frédéric Hamidi Avatar answered Jan 02 '23 09:01

Frédéric Hamidi