Here is the source code
function MetadataParser(version, channel, keyField) {
let _version = version;
let _channel = channel;
let _keyField = keyField;
this.setVersion = function (version) {
_version = version;
};
this.getVersion = function () {
_version = version;
};
this.setChannel = function (channel) {
_channel = channel;
};
this.getChannel = function () {
return _channel;
};
this.setKeyField = function (keyField) {
_keyField = keyField;
};
this.getVersion = function () {
return _keyField;
};
this.getKeyFields = function (jsonObject) {
let keyField = [];
jsonObject.array.forEach((element) => {
keyField.push(element.channel);
});
return keyField;
};
}
const metadataParser = new MetadataParser("A", "B", "C");
console.log(
metadataParser.getKeyFields([
{ channel: "A" },
{ channel: "B" },
{ channel: "C" },
])
);
When I iterate the array using normal for loop the code works fine! The error occurs whenever i try to call the getKeyFields method.