0

So my challenge right now is unable to add array with another array into another new array.

my code:

var disabletimerange = { basedonservicetype: "", basedonservicer: "" }
var arr = [{"StartTime":"09:00:00","EndTime":"09:10:00"},{"StartTime":"10:00:00","EndTime":"15:00:00"}]
for (var xx = 0; xx < arr.length; xx++) {
    var bookedStartTime, bookedEndTime
    bookedStartTime = arr[xx].StartTime.slice(0, -3)
    bookedEndTime = arr[xx].EndTime.slice(0, -3)

    if (disabletimerange.basedonservicer === "") {
        var disabletimealreadybookedtiming = "[" + '"' + bookedStartTime + '"' + "," + '"' + bookedEndTime + '"' + "]"
        disabletimerange.basedonservicer = JSON.parse(disabletimealreadybookedtiming)
    } else {
        var disabletimealreadybookedtiming = "[" + '"' + bookedStartTime + '"' + "," + '"' + bookedEndTime + '"' + "]"
        disabletimerange.basedonservicer = "[" + "[" + disabletimerange.basedonservicer + "]" + "," + disabletimealreadybookedtiming + "]"
        disabletimerange.basedonservicer = JSON.parse(disabletimerange.basedonservicer)
}

Uncaught SyntaxError: Unexpected number in JSON at position 3 --> at the last line it cannot parse.

In short, what i want is basically 2 array stick tgt instead of adding into it

var y = ["hi", "123"]
var x = ["yo", "312"]

this
[["hi", "123"], ["yo", "312"]] instead of ["hi", "123", "yo", "312"]

and it must be array. not text form

0

2 Answers 2

4

You can do:

var y = ["hi", "123"]
var x = ["yo", "312"]

var result = [x, y]

console.log(result)

Sign up to request clarification or add additional context in comments.

Comments

0

As you described

How to add array with another array into a new array?

  • create a new array

  • push your arrays into this new array one by one

let x = [1,2];
let y = [3.4];

let z = [];
z.push(x)
z.push(y);

console.log(z);

Comments

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.