Home >Web Front-end >JS Tutorial >How Can I Retrieve a Specific GET Parameter Value in JavaScript?
When encountering URLs containing GET parameters, such as "www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5," retrieving the entire value for the "c" parameter can prove challenging. JavaScript, alone, lacks intrinsic functionality for handling this task.
However, modern browsers and Node.js provide the URL object within the Web API. This object allows for efficient interaction with URLs:
var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; var url = new URL(url_string); var c = url.searchParams.get("c"); console.log(c);
The above is the detailed content of How Can I Retrieve a Specific GET Parameter Value in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!