TypeScript
Array.map & Array.filter

by Benny Neugebauer

let serializedPreKeys: Array<Object> = [];

initialPreKeys.forEach((preKey) => {
  const preKeyJson: { id: number, key: string } = this.cryptobox.serialize_prekey(preKey);
  if (preKeyJson.id !== 65535) serializedPreKeys.push(preKeyJson);
});

const serializedPreKeys: Array<Object> = initialPreKeys.map((preKey) => {
  const preKeyJson: { id: number, key: string } = this.cryptobox.serialize_prekey(preKey);
  if (preKeyJson.id !== 65535) return preKeyJson;
  return undefined;
}).filter((serializedPreKey) => serializedPreKey);