How to dynamically split an array?

 const keywords = new Set(["x", "y", "z"]);

 let acc = [];
 const result = [];

 for(const el of array) {
   if(keywords.has(el)) {
     result.push(acc = [el]);
   } else acc.push(el);
 }

Just another way to do it. You could use slice:

var a = ["x", "foo", "y", "bar", "baz", "z", "0"];
var breakpoints = ['x', 'y', 'z'];
var res = [];
for(var i = 0; i < breakpoints.length - 1; i++) {
  res = res.concat([a.slice(a.indexOf(breakpoints[i]), a.indexOf(breakpoints[i+1]))]);
}
res = res.concat([a.slice(a.indexOf(breakpoints[i]))]);
console.log(res);

I'm too late, but I will show a totally different approach from other answers. In this approach the input array is converted to string using join() and the result is obtained using, mainly, regular expressions with the split() method:

const input = ["x", "foo", "y", "bar", "baz", "z", "0"];
const keyRegex = /(?=#x#)|(?=#y#)|(?=#z#)/;

let res = ("#" + input.join("#") + "#")          // #x#foo#y#bar#baz#z#0#"
    .split(keyRegex)                             // [#x#foo, #y#bar#baz, #z#0#]
    .map(str => str.split("#").filter(Boolean));

console.log(JSON.stringify(res));

And here is another approach using map() over an array with the keys. Note I have passed a copy of input array to the map method and I used it as the this argument. Also, I'm using splice() over this to remove the already analyzed section and perform futures findIndex() over a shortened array. However, none of this things can be better than a solution with reduce() or a standard loop over the input array.

const input = ["x", "foo", "y", "bar", "baz", "z", "0"];
const keys = ["x", "y", "z"];

let res = keys.map(function(k, i)
{
    let a = this.findIndex(x => x === k);
    let b = this.findIndex(x => x === keys[i+1]);
    return this.splice(a, b >= 0 ? b : this.length);
}, input.slice());

console.log(JSON.stringify(res));

You could take an array and a closure over the index for the key strings and push an empty array if a key is found.

var array = ["x", "foo", "y", "bar", "baz", "z", "0"],
    keys = ["x", "y", "z"],
    result = array.reduce((i => (r, s) => {
        if (s === keys[i]) {
            r.push([]);
            i++;
        }
        r[r.length - 1].push(s);
        return r;
    })(0), []);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }