0

I need to find a way to transform var input =["tag1", "tag2", "tag3"] so that it becomes "tag1", "tag2", "tag3"

At the end I should have var output = "tag1", "tag2", "tag3" enter code here

I tried push, splice, join...nothing worked.

Some words on why: It can seem weird but I need to use some third party tool querying convention

object.containsAll('activities', 'tag1', 'tag2', 'tag3')

So the query is failing because I can't write object.containsAll('activities', input), as input here is an array

1
  • 1
    I know...that's why i added the "some words on why".I need to have a query that takes the items of the array to make: object.containsAll('activities', 'tag1', 'tag2', 'tag3') Commented Sep 4, 2018 at 22:30

1 Answer 1

3

Why not spread the input array into the argument list, no transformation needed?

object.containsAll('activities', ...input);

Or, without spread:

const argumentsArr = input.slice(); // avoid mutating the original array
argumentsArr.unshift('activities');
object.containsAll.apply(object, argumentsArr);
Sign up to request clarification or add additional context in comments.

6 Comments

I don't know this ... => what's the name of this technique
@Mathieu => is the lambda, but it is not really related to the question. Or perhaps you mean the ... it is the spread operator.
wow never knew this thing. thanks i'll try this out and will read more about these techniques
@Mathieu Just read What does this symbol mean in JavaScript? and the documentation on MDN about expressions and operators.
|

Your Answer

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.