0

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

samayo
16.5k13 gold badges95 silver badges115 bronze badges
asked Aug 21, 2017 at 10:54
1
  • Can you provide the result of your rest service? Commented Aug 21, 2017 at 11:07

2 Answers 2

1

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
answered Aug 21, 2017 at 11:06
Sign up to request clarification or add additional context in comments.

Comments

0

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)

answered Aug 21, 2017 at 10:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.