rteduce

Benchmark created on


Preparation HTML

<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>

Setup

const iframeAttr=      [{
        id: '062ca9b2-ccc8-4557-88f7-48086a3fdb13',
        fields: {
          key: {
            value: 'frameBorder',
          },
          value: {
            value: '0',
          },
        },
        templateName: 'Attribute KeyValuePair',
        templateId: '{D09D038A-8FD1-43BE-9F77-B7FDF57C6B12}',
        url: '/sitecore/content/global-references/global-content/style-attributes/frameborder',
      },
      {
        fields: {
          key: {
            value: 'data-test',
          },
          value: {
            value: 'testDataAttr',
          },
        },
      }];

Test runner

Ready to run.

Testing in
TestOps/sec
lodash
  reduce(
    iframeAttr,
    (attrs, attr) => {
      const { key, value } = attr.fields || {};
      if (key?.value) return { ...attrs, [key.value]: value?.value };

      return attrs;
    },
    {}
  );
ready
array
iframeAttr.map(a=>a.fields).reduce(
    (attrs, {key,value.value}) => Object.assign(attrs, {[key.value]:value.value}),{});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.