Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Copy and rename specified keys for every element in a provided array.

License

NotificationsYou must be signed in to change notification settings

stdlib-js/array-base-rekey

 
 

Repository files navigation

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!

rekey

NPM versionBuild StatusCoverage Status

Copy and rename specified keys for every element in a provided array.

Usage

To use in Observable,

rekey=require('https://cdn.jsdelivr.net/gh/stdlib-js/array-base-rekey@umd/browser.js')

To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:

varrekey=require('path/to/vendor/umd/array-base-rekey/index.js')

To include the bundle in a webpage,

<scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-base-rekey@umd/browser.js"></script>

If no recognized module system is present, access bundle contents via the global scope:

<scripttype="text/javascript">(function(){window.rekey;})();</script>

rekey( arr, mapping )

Copies and renames specified keys for every element in a provided array.

varx=[{'x':1,'y':2},{'x':3,'y':4}];varmapping={'x':'a','y':'b'};varout=rekey(x,mapping);// returns [ { 'a': 1, 'b': 2 }, { 'a': 3, 'b': 4 } ]

The function has the following parameters:

  • arr: input array.
  • mapping: object mapping existing keys to new key names.

Notes

  • The functiononly copies and renames those keys which are present in a provided mapping object. Any keys which arenot present in the provided mapping object, but are present in the original objects, areomitted during object creation.
  • The function assumes that each object has the keys specified in a provided mapping object.
  • The function performsshallow copies of key values.

Examples

<!DOCTYPE html><htmllang="en"><body><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/random-base-discrete-uniform@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-base-rekey@umd/browser.js"></script><scripttype="text/javascript">(function(){functionclbk(idx){return{'x':idx,'y':discreteUniform(0,10)};}varx=filledBy(10,clbk);varmapping={'x':'a','y':'b'};varout=rekey(x,mapping);// returns [...]})();</script></body></html>

Notice

This package is part ofstdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to developstdlib, see the main projectrepository.

Community

Chat


License

SeeLICENSE.

Copyright

Copyright © 2016-2025. The StdlibAuthors.

About

Copy and rename specified keys for every element in a provided array.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp