
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
dra-dual-reference-array
Advanced tools
Makes an array's object available through the same array's namespace, through a property, keeping the index untouched. This is just a pattern, not a API neither a framework. I never saw something like this before, so decided to study it.
Makes an array's object available through the same array's namespace, through a property, keeping the index untouched. This is just a pattern, not a API neither a framework. I never saw something like this before, so decided to study it.
Read my detailed article at Medium
https://tonicdev.com/jotafeldmann/dra-dual-reference-array
npm install dra-dual-reference-array
var DRA = require ('dra-dual-reference-array');
var
fields = [ // Our array
{
id : 0,
fieldName : 'email', // It's a common property, with unique values
label : 'Email',
data : { dummy : 'whoomy' }
},
{
id : 1,
fieldName : 'another', // Again
label : 'Another field'
}
]
;
// At this time, I just can access the array, through the index
console.log ( fields[0] ); // Object {...}
// Now, the magic
fields = DRA ( fields , 'fieldName' );
// Then, the same array's value is available by it's common property unique name
console.log ( fields._email ); // Object {...}
// If some property is changed, the change is reflected in both ways
fields._email.label = 'Devs are disciples of Thomas the Apostle';
console.log ( fields._email.label , fields[0].label );
// 'Devs are disciples of Thomas the Apostle' , 'Devs are disciples of Thomas the Apostle'
// The versa is the same, the ARRAY's REFERENCE can be accessed in DUAL ways
fields[0].label = 'We need to see to believe, show me the code';
console.log ( fields._email.label , fields[0].label );
// 'We need to see to believe, show me the code' , 'We need to see to believe, show me the code'
// And the object comparison remains
fields[0] === fields._email // True
// BONUS: it keeps the array's length untouched
fields.length // 2
// BONUS: You can use the explicit method to achieve the same result and improve readability
// Suggestion by Raul Oliver
DRA.convertPropsToObject ( fields , 'fieldName' );
MIT License © Jorge Feldmann (jotafeldmann)
FAQs
Makes an array's object available through the same array's namespace, through a property, keeping the index untouched. This is just a pattern, not a API neither a framework. I never saw something like this before, so decided to study it.
The npm package dra-dual-reference-array receives a total of 0 weekly downloads. As such, dra-dual-reference-array popularity was classified as not popular.
We found that dra-dual-reference-array demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.