Reputation: 365
im doing a check if a object matches a default value, however i don't care about upper/lower case differences.
Current function:
function checkSingleDifference(property) {
if ($scope.defaultsAvailable === false) {
console.log("default are not available!");
return false;
} else if (!$scope.machinedefaults || !$scope.machine) {
return false;
}
else {
return $scope.machinedefaults[property] !== undefined && $scope.machinedefaults[property] !== $scope.machine[property];
}
}
The return value in CheckSingleDifference is the objects that do not match.
since the objects that are being checked are arrays, toUpperCase does not work.
is it possible to handle this in a java script only way, or is it necessary to modify the objects in php?
expected values are 2 strings within a object so for example:
machinedefaults[property] = "One"
machine[property] = "one"
then i don't want it to return these values.
thanks.
UPDATE
solution:
function checkSingleDifference(property) {
if ($scope.defaultsAvailable === false) {
console.log("default are not available!");
return false;
} else if (!$scope.machinedefaults || !$scope.machine) {
return false;
}
if($scope.machinedefaults[property] !== undefined && $scope.machinedefaults[property].toLowerCase() !== $scope.machine[property].toLowerCase()) {
return $scope.machinedefaults[property] !== undefined && $scope.machinedefaults[property] !== $scope.machine[property] ;
}
}
Upvotes: 0
Views: 642
Reputation: 66355
You can still convert the strings it doesn't matter that they are in an array (or an object):
return $scope.machinedefaults[property] !== undefined &&
$scope.machinedefaults[property].toLowerCase() !== $scope.machine[property].toLowerCase();
Upvotes: 2