Listado de la etiqueta: Object


In JavaScript, an object comprises keys and values which are known as properties. To deal with the keys and values of an object, JavaScript provides various methods. These methods retrieve the enumerable properties in an array form. .

The Object.keys() method is employed to access the keys of an object in JavaScript. The ordering in the Object.keys() method is the same as the standard loop. This tutorial  will illustrate how to get Object keys in JavaScript using the Object.keys() method. The outcomes of this article are given as follows:

  • How does Object.keys() method works
  • How to use JavaScript Object.keys() method

How to get object keys in JavaScript

The Object keys can be attained  using the Object.keys() method. In JavaScript, the Object.keys() method returns an array containing all the object’s own enumerable property names. The working mechanism and functionality of the Object.keys() method are provided in the upcoming sections.

How does JavaScript Object.keys() method work
The Object.keys() method retrieves the countable property values of an object and returns the output in an array form.

The syntax of the JavaScript Object.keys() method is given as follows:

Here, ‘obj’ is a parameter whose keys are to be returned

JavaScript Object.keys() method returns the array of a string to represent the countable keys upon a specified object.

In JavaScript, there are two properties of Object keys that are mentioned in the following.

  • Enumerable: A countable property of an object that is set to be “True”.
  • Non-Enumerable: The uncountable property of an object that is set to be “False”.

How to use JavaScript Object.keys() method
The Object.keys() method accepts the arguments as an input and returns an array with unique keys. An object can be a number, a symbol, or a string. It could not be null or undefined. In this section, you will learn how to get the Object keys in JavaScript using the Object.keys() method with examples.

Example: How to get Object keys of enumerable properties in JavaScript
In Javascript, the Object.keys() method is used to get the Object keys of the array object. In this example, we will show you how to get the object keys of an object:

Student = {
    name: «ALI»,
    age: 26,
    marks: 85,
  };
 
  // get all keys of Student
  std = Object.keys(Student);
  console.log(std);

In this code, an object “Student” contains three keys and three values. The Object.keys() method is applied on the “Student” object to retrieve the keys.

After applying the Object.keys() method, the keys of an object ‘student’ are displayed on the console.

Example: How to get Object keys of Non-enumerable properties in JavaScript
In JavaScript, the Object.keys() method returns only enumerable properties of the object. Let’s refer to the following code to get the keys of uncountable properties of an object.

keys = Object.create({}, {
    getName: {
        value: function () { return this.name; }
    }
});
keys.name = ‘LinuxHint’;

console.log(Object.keys(keys));

This code narrates that an object is created in which the function has a null value. However, there must be a value to an object. Otherwise, it will not return the property key. The example shows that if the called function is empty, it will simply return the name only.

The returned output showed that when a null or undefined value is passed the function only returns the “[‘name’]”.

Conclusion

Object.keys() method is a built-in function of the JavaScript that is utilised  to access the Object keys. This method returns an array of strings. This article provides a deep knowledge of how to get object keys in JavaScript. For a better understanding, we have illustrated the working and usage of Object.entries() method with suitable examples.



Source link


Set Objects in JavaScript are very much similar to the arrays the major difference between these two is that the set objects can’t hold the duplicate values however arrays can. In JavaScript, the set objects allow us to store only unique values in them. These unique values can be of any type like primitive data types(int, strings, etc), object references, complex object/data types such as object, arrays, literals, etc. In JavaScript several set object methods can be used to achieve different functionalities, for example, add(), delete(), forEach(), etc.

In this article, we will cover the below listed aspects of set object methods in JavaScript:

So, let’s begin!

How to use new Set() to create a set in JavaScript

To work with any of the Set object methods, firstly, we have to create a set. To do so, we can use the “new Set()” constructor.

Example

The below given piece of code will explain how to create a Set in JavaScript using the “new Set()” constructor:

<script>
let employeeNames = new Set();

console.log(employeeNames);
</script>

The above code will create an empty set as shown in the following output:

The output shows that an empty Set is created, now we can perform any functionality on that set using different set object methods such as append elements, remove elements, etc.

How to use add() method to add elements in a set

JavaScript provides a method named add() that is used to append the elements in a set.

Example

Now, we will extend the above example a little bit more to add/append the elements to the Set:

employeeNames.add(«Steve»);
employeeNames.add(«Michael»);
employeeNames.add(«Smith»);
employeeNames.add(«Paul»);
employeeNames.add(«Ambrose»);
console.log(employeeNames);

In this example, we added five elements in the set named “employeeNames” using the add() method. Afterward, we utilized the console.log() method to print all the elements stored in the “employeeNames” set on the browser’s console:

The output verifies the working of the add() method.

How to use delete() method to remove elements from a set

In JavaScript, the delete() method can be used to remove some specific elements from the set object.

Example

Let’s suppose we want to remove “Smith”, and “Paul” from the set “employeeNames”. To do so, we can utilize the delete() method:

employeeNames.delete(«Smith»);
employeeNames.delete(«Paul»);
console.log(employeeNames);

The above code block will generate the following output:

The above snippet shows that the delete() method has removed “Smith” and “Paul” from the Set successfully.

How to use clear() method to delete all elements from a set

In JavaScript, the clear() method can be used to remove all the elements of a set object.

Example

In this example, we will utilize the clear() method to delete all the items from the set “employeeNames”:

employeeNames.clear();
console.log(employeeNames);

The above code snippet will produce the following results:

The output shows the Set’s size equal to zero; it authenticates the working of the clear() method.

How to check the existence of some specific value in a set using has() method

In JavaScript, the has() method can be used to check whether a specific element exists in the set or not.

Example

In this example, we will check the existence of two elements i.e. “Smith”, and “Bryn” using the has() method:

console.log(employeeNames.has(«Smith»));
console.log(employeeNames.has(«bryn»));

The piece of code will return true if the specified value exists in the set and it will return false if the specified value doesn’t exist in the targeted set:

The output shows that the has() method returns true for the element “smith” as it exists in the set while “Bryn” doesn’t exist in the targeted set therefore the has() method returns false for it.

How to find the size of a set

In JavaScript, the size property can be used to check the size/length of some specific set.

Example

In this example we will utilize the size property to check the size of the set “employeeNames”:

Following will be the corresponding output for the above-given code:

The output shows the appropriate size of the specified set i.e “employeeNames” set.

Conclusion

In JavaScript, the set objects allow us to store only unique values in them. These unique values can be of any type like primitive data types(int, strings, etc), object references, complex object/data types such as objects, arrays, literals, etc. In JavaScript, there is a wide range of set object methods that can be used to perform different functionalities. For example, Add(), delete(), and clear(), methods are used to append and remove elements, the has() method is used to check the existence of an element in a specific set, etc. This write-up explained the working of various set object methods with the help of suitable examples.



Source link


Welcomes SoftBank Group to its member ranks

TOKYO, May 25, 2022 – The SODA Foundation, which hosts the SODA Open Data Framework (ODF) for data mobility from edge to core to cloud, today announced two new open source projects: Kahu and Como. Kahu streamlines data protection for Kubernetes and its application data, and Como is a supuesto data lake project to enable seamless access to data stored in different clouds. The SODA Foundation also welcomes SoftBank Group as an end-user supporter and key collaboration partner on the Como project.

According to the 2021 SODA Data and Storage Trends Report, two of the top challenges in managing data in containers and cloud-native environments are availability (46%) and management tools (38%).  In direct response to the report findings, the SODA Foundation community collaborated to introduce new tooling options through the Kahu project to improve backup and restore practices critical to data availability.  Furthermore, as enterprises become more data-driven and data growth for some enterprises can exceed 10PB per year, object data management offered by the Como Project will play an important role in performance and scalability requirements for cloud-native environments.

“Data collection, management, and consumption is becoming the new competitive battlefield in IT”, said Steven Tan, chairman, SODA Foundation. “We’re excited to announce Kahu and Como as the latest advances in open source data management and storage. Our 28 members are also excited to welcome the engineers and open source community within SoftBank Group to the Foundation.” 

“Data is the fuel of our universal digital economy and harnessing its power requires collaboration on a massive scale”, said Kuniyoshi Suzuki, Senior Director, Cloud Engineering , SoftBank Group.  “Softbank is excited to be joining a community of open source software developers focused on enabling improvements toward data storage, recovery, and retention in cloud environments. We look forward to collaborating with the SODA Foundation and its members, while contributing to the future of this important community.”

New Open Source Releases

In addition to the announcement of Kahu and Como projects, the SODA Foundation also announced the:

  • Release of SODA Framework Madagascar v1.7.0: Formerly Open Data Framework (ODF), SODA Framework comprises independent projects initiated by the community to solve common data and storage problems faced by end users. It includes:
    • Terra: a universal SDS controller for connecting storage to Kubernetes, OpenStack, and VMware environments.
    • Delfin: a performance pedagogo for heterogeneous storage infrastructure in a single pane of glass.
    • Strato: a multi-cloud data controller using a common S3-compatible interface to connect to cloud storage.
    • Kahu : new project to streamline data protection for Kubernetes and application data.
  • Expansion of its Eco Project Initiative with the introduction of more open source projects: 

DAOS: a software-defined object store designed from the ground up for massively distributed Non Volatile Memory (NVM), providing features such as transactional non-blocking I/O, advanced data protection with self-healing on top of commodity hardware, end-to-end data integrity, fine-grained data control and elastic storage.

YIG: extends Minio backend storage aggregating multiple Ceph clusters to form a massive storage resource pool that can easily scale up to exabyte (EB) levels with minimal performance disruption.

CubeFS: a cloud-native storage platform used as the underlying storage infrastructure for online applications, database or data processing services and machine learning jobs orchestrated by Kubernetes.

Karmada: a Kubernetes management system that enables organizations to run cloud-native applications across multiple Kubernetes clusters and clouds, with no changes to your applications.

SBK: an open source software framework for the performance benchmarking of any storage system.

Conferences and Survey

  • SODACODE: this week, developers from around the world will participate in SODACODE 2022 – the Data & Storage Hackathon on May 25 – 26.  The first-of-its-kind coding event organized by SODA Foundation is open to developers from all levels ranging from beginner to advanced. The hackathon will conclude with project demonstrations, presentation sessions, panel discussions and an award ceremony for the hackathon winners.
  • Trend Survey: The SODA Foundation will release its second-annual Data and Storage Trends Survey on June 30, 2022.
  • SODACON: a technical conference held by SODA Foundation, will be held this year in Yokohama, Japan on December 7, 2022. The conference will bring together industry leaders, developers and end users to present and discuss the most recent innovations, trends, and concerns as well as practical challenges and solutions in the field of Data and Storage Management in the era of cloud-native, IoT, big data, machine learning, and more.

Additional Resources

  • Join the SODA Foundation
  • Attend SODACODE 2022 – The Data & Storage Hackathon
  • Read the 2021 Data and Storage Trends Report

About the SODA Foundation

Previously OpenSDS, the SODA Foundation is part of the Linux Foundation and includes both open source software and standards to support the increasing need for data autonomy. SODA Foundation Premiere members include China Unicom, Fujitsu, Huawei, NTT Communications and Toyota Motor Corporation. Other members include China Construction Bank Fintech, Click2Cloud, GMO Pepabo, IIJ, MayaData, LinBit, Scality, Sony, Wipro and Yahoo Japan.

Media Contact

info@sodafoundation.io

###

The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see its trademark usage page: www.linuxfoundation.org/trademark-usage. Linux is a registered trademark of Linus Torvalds.



Source link