JSFiddle - React, Tailwind, and code Playground

by dmitri_pavlutin

JavaScript

const addMethod = 'add';
const getMethod = 'get';
const collection = {
  items: [],
  [addMethod](...items) {
    this.items.push(...items);
  },
  [getMethod](index) {
    return this.items[index];
  }
};

collection[addMethod]('C', 'Java', 'PHP');
console.log(collection[getMethod](1)); // => 'Java'