Codota Logo For Javascript
Array.reduce
Code IndexAdd Codota to your IDE (free)

How to use
reduce
function
in
Array

Best JavaScript code snippets using builtins.Array.reduce(Showing top 15 results out of 16,497)

origin: strapi/strapi

Object.keys(formErrors)
  .filter(key => key.includes('headers'))
  .reduce((obj, key) => {
   obj[key] = formErrors[key];

   return obj;
  }, {})
origin: Flood-UI/flood

processTransferRateResponse(transferRate = [], options) {
  this.emit(clientGatewayServiceEvents.PROCESS_TRANSFER_RATE_START);

  return transferRate.reduce((accumulator, value, index) => {
   const key = options.propLabels[index];
   const transformValue = options.valueTransformations[index];

   accumulator[key] = transformValue(value);

   return accumulator;
  }, {});
 }
origin: klaussinani/signale

_getLongestLabel() {
  const {_types} = this;
  const labels = Object.keys(_types).map(x => _types[x].label);
  return labels.reduce((x, y) => x.length > y.length ? x : y);
 }
origin: parse-community/parse-server

providers.reduce((memo, provider) => {
  if (!authData[provider]) {
   return memo;
  }

  const queryKey = `authData.${provider}.id`;
  const query = {};
  query[queryKey] = authData[provider].id;
  memo.push(query);
  return memo;
 }, []).filter(q => {
  return typeof q !== 'undefined';
 })
origin: strapi/strapi

Object.keys(strapi.components).reduce((acc, entity) => {
    Object.keys(strapi.components[entity].attributes).forEach(attribute => {
     const attr = strapi.components[entity].attributes[attribute];

     if ((attr.collection || attr.model || '').toLowerCase() === model.toLowerCase()) {
      acc.push(strapi.components[entity].globalId);
     }
    });

    return acc;
   }, [])
origin: Automattic/wp-calypso

const combineXPosts = ( postKeys ) =>
  postKeys.reduce( ( accumulator, postKey ) => {
    const lastPostKey = last( accumulator );
    if ( sameXPost( lastPostKey, postKey ) ) {
      accumulator[ accumulator.length - 1 ] = addDuplicateXPostToPostKey( lastPostKey, postKey );
    } else {
      accumulator.push( postKey );
    }
    return accumulator;
  }, [] )
origin: strapi/strapi

/**
 * Utility function to compose validators
 */
const composeValidators = (...fns) => attr => {
 return fns.reduce((validator, fn) => {
  return fn(attr, validator);
 }, yup.mixed());
}
origin: strapi/strapi

Object.keys(strapi.api || []).reduce((acc, key) => {
  for (let index in strapi.api[key].services) {
   acc[index] = strapi.api[key].services[index];
  }

  return acc;
 }, {})
origin: strapi/strapi

Object.keys(files).reduce((acc, key) => {
  const fullPath = _.toPath(key);

  if (fullPath.length <= 1 || fullPath[0] !== 'files') {
   throw strapi.errors.badRequest(
    `When using multipart/form-data you need to provide your files by prefixing them with the 'files'.
For example, when a media file is named "avatar", make sure the form key name is "files.avatar"`
   );
  }

  const path = _.tail(fullPath);
  acc[path.join('.')] = files[key];
  return acc;
 }, {})
origin: strapi/strapi

const init = (initialState, permissions) => {
 const collapses = Object.keys(permissions)
  .sort()
  .reduce((acc, current, index) => {
   return acc.concat({
    name: current,
    isOpen: index === 0,
   });
  }, []);

 return { ...initialState, collapses };
}
origin: strapi/strapi

Object.keys(strapi.plugins).reduce((acc, current) => {
   const isDocumentationNeeded = this.isPluginDocumentationNeeded(current);

   if (isDocumentationNeeded) {
    return acc.concat(current);
   }

   return acc;
  }, [])
origin: porsager/postgres

['B', 'C', 'Q', 'P', 'F', 'p', 'D', 'E', 'H', 'S'].reduce((acc, x) => {
 const v = x.charCodeAt(0)
 acc[x] = () => {
  buffer[0] = v
  b.i = 5
  return b
 }
 return acc
}, {})
origin: graphile/postgraphile

function trimNulls(obj: Record<string, any>): Record<string, any> {
 return Object.keys(obj).reduce((memo, key) => {
  if (obj[key] != null) {
   memo[key] = obj[key];
  }
  return memo;
 }, {});
}
origin: strapi/strapi

const removeNullKeys = obj =>
 Object.keys(obj).reduce((acc, current) => {
  if (obj[current] !== null && current !== 'plugin') {
   acc[current] = obj[current];
  }

  return acc;
 }, {})
origin: strapi/strapi

const formatMessagesWithPluginId = (pluginId, messages) => {
 return Object.keys(messages).reduce((acc, current) => {
  acc[`${pluginId}.${current}`] = messages[current];

  return acc;
 }, commonTrads);
}
builtins(MDN)Arrayreduce

JSDoc

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

Most used builtins functions

  • Console.log
  • Console.error
  • Promise.then
    Attaches callbacks for the resolution and/or rejection of the Promise.
  • Promise.catch
    Attaches a callback for only the rejection of the Promise.
  • Array.push
    Appends new elements to an array, and returns the new length of the array.
  • Array.length,
  • Array.map,
  • String.indexOf,
  • fetch,
  • Window.location,
  • Window.addEventListener,
  • ObjectConstructor.keys,
  • Array.forEach,
  • Location.reload,
  • Response.status,
  • Navigator.serviceWorker,
  • ServiceWorkerContainer.register,
  • ServiceWorkerRegistration.installing,
  • ServiceWorkerContainer.controller

Popular in JavaScript

  • moment
    Parse, validate, manipulate, and display dates
  • readable-stream
    Streams3, a user-land copy of the stream library from Node.js
  • async
    Higher-order functions and common patterns for asynchronous code
  • js-yaml
    YAML 1.2 parser and serializer
  • mongodb
    The official MongoDB driver for Node.js
  • lodash
    Lodash modular utilities.
  • mkdirp
    Recursively mkdir, like `mkdir -p`
  • fs
  • debug
    small debugging utility
  • Top plugins for WebStorm
    The challenge is finding the best plugins for JavaScript development on Intellij IDEs. Who wants to sit there and go over hundreds of plugins to pick the best?
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJavascript Code Index
Get Codota for your IDE now