I am getting results from rest service into one string, it contain a number(id) or multiple number(multiple id) seprated by commas.
Now i want to pass above id or multiple id into function as a parameter so it returns me rolename, so how can i pass multiple id to functionin javascript....Kindly help as i am new to programming
var roleNamedata = 'javascript=xdmp.roleName(' + '"' + id+ '"' + ')';
how can i pass array to above function, and how to convert string into array
-
Can you provide the result of your rest service?kevinSpaceyIsKeyserSöze– kevinSpaceyIsKeyserSöze2017年08月21日 11:07:06 +00:00Commented Aug 21, 2017 at 11:07
2 Answers 2
the following code will help u to convert a comma separated string into an array,
var string = "1,2,3,4,5";
var array = string.split(","); // string to array conversion
function takesArray(a) { // taking an array as parameter
console.log(a);
}
takesArray(array); // passing array as argument
Comments
use Array.forEach
var a = ['a', 'b', 'c'];
a.forEach(function(element) {
console.log(element);
});
// a
// b
// c
or Array.map var a = ['a', 'b', 'c'];
a.map(function(element) {
console.log(element);
});
// a
// b
// c
console.log() will print value into developers tools console (on chrome hit F12)