Iterate over a Javascript Object and perfom conditional on values

So i have a JS Object like that :

let object =
    {
      "key1":"value1",
      "key2":"value2",
      "key3":"value3"
    }

For iterating, i use this : for (let i = 0; i < Object.keys(object).length; i++)

Now, what i want to do is basically this :

let value;
if (data === undefined || data === "") {
        value = []
} else if (data.includes(",")) {
    value = data.split(",")
} else if (data.includes(".")) {
    value = data.split(".")
} else {
    value = data.split(" ");
}

So, i tried Object.values(entries_array).split(",") but split is not an Object method. So if you can help me to find a solution.
Thanks in advance.

23 thoughts on “Iterate over a Javascript Object and perfom conditional on values”

Leave a Comment